class smx_tomcat {
  require smx_java

  package { "tomcat-admin-webapps" :
    ensure => latest,
  }
  package { "tomcat-server" :
    name   => 'tomcat',
    ensure => latest,
  }

  service { 'tomcat' :
    enable  => true,
    ensure  => running,
    require => Package['tomcat-server'],
  }

  exec { "sed" :
    command => "sed -i -e '/Connector port=\"8080\"/a URIEncoding=\"UTF-8\"' /etc/tomcat/server.xml",
    path    => [ "/bin","/sbin","/usr/bin","/usr/sbin" ],
    require => Package["tomcat-admin-webapps"],
    unless  => "grep URIEncoding /etc/tomcat/server.xml",
  }

  exec { "tomcat_status" :
    command => "sed -i -e '$ i<user username=\"tomcat\" password=\"tomcat123312\" roles=\"manager-status\"/>' /etc/tomcat/tomcat-users.xml",
    path    => [ "/bin","/sbin","/usr/bin","/usr/sbin" ],
    require => Package["tomcat-admin-webapps"],
    unless  => "grep tomcat123312 /etc/tomcat/tomcat-users.xml",
  }

  if $fqdn =~ /^[a-z0-9]+\.[a-z0-9-]+\.foxitcloud\.com/ {
    exec { 'sed8105':
      command => "sed -i -e '22s/8005/8105/' /etc/tomcat/server.xml",
      path    => [ "/bin","/sbin","/usr/bin","/usr/sbin" ],
      require => Exec['sed'] }

    exec { 'sed8180':
      command => "sed -i -e 's/Connector port=\"8080\"/Connector port=\"8180\"/' /etc/tomcat/server.xml",
      path    => [ "/bin","/sbin","/usr/bin","/usr/sbin" ],
      require => Exec['sed8105'],
      notify  => Service['tomcat'] }
  }
  else {
    notify { "Tomcat package install complate!": }
  }

}
